package days.of.evil.ui;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Device;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.part.ViewPart;

import days.of.evil.core.ressource.external.LoadRessources;
import days.of.evil.core.ressource.external.Ressource;
import days.of.evil.util.number.DoubleUtil;

public class View extends ViewPart {
	public static final String ID = "days.of.evil.ui.view";

	/**
	 * This is a callback that will allow us to create the viewer and initialize
	 * it.
	 */
	public void createPartControl(Composite parent) {
		parent.setLayout(new FillLayout(SWT.VERTICAL));
		initColumn(parent);
		boolean choiceColor = false;
		for (String res : LoadRessources.getInstance().getListRessources().keySet()) {
			
			addLine(parent, LoadRessources.getInstance().getListRessources().get(res), choiceColor);
			choiceColor = !choiceColor;
		}
	}

	private void initColumn(Composite parent) {
		Composite compo = new Composite(parent, SWT.NONE);
		compo.setLayout( new FillLayout(SWT.HORIZONTAL));
		compo.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
		
		Label label = new Label(compo, SWT.NONE);
		label.setText("Ressource");
		
		//label.setFont(new Font(Activator.getDefault().getWorkbench().getDisplay(),"arial", SWT.ITALIC,17));
		
		new Label(compo, SWT.NONE);
		
		Label labelProd = new Label(compo, SWT.NONE);
		labelProd.setText("Nombre diab");
		
		Label labelProd2 = new Label(compo, SWT.NONE);
		labelProd2.setText("Cout de fabrication");
		
		Label labelProd3 = new Label(compo, SWT.NONE);
		labelProd3.setText("Prix de vente");
		
		
	}

	private void addLine(Composite parent, Ressource res, boolean choiceColor) {
		Color color = null;
		Device device = PlatformUI.getWorkbench().getDisplay();
		if (choiceColor) {
			color = new Color(device, 255,241,141);
		} else {
			color = new Color(device,237,211,140);
		}
		Composite compo = new Composite(parent, SWT.NONE);
		compo.setLayout( new FillLayout(SWT.HORIZONTAL));
		compo.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, true));
		
		Label label = new Label(compo, SWT.NONE);
		label.setText(res.getName());
		label.setBackground(color);
		
		new Label(compo, SWT.NONE).setBackground(color);
		
		Label labelProd = new Label(compo, SWT.NONE);
		labelProd.setBackground(color);
//		labelProd.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
		labelProd.setText(String.valueOf(res.getNbDiablotinPerHour()));
		
		Label labelProd2 = new Label(compo, SWT.NONE);
		labelProd2.setBackground(color);
		labelProd2.setText(DoubleUtil.formatDouble(res.getMakingPrice()));
		
		Label labelProd3 = new Label(compo, SWT.NONE);
		labelProd3.setBackground(color);
		labelProd3.setText(DoubleUtil.formatDouble(res.getSellingPrice()));
	}

	/**
	 * Passing the focus request to the viewer's control.
	 */
	public void setFocus() {
	}
}